import {
    defineStore
} from "pinia";
import {
    ref
} from "vue";

export const goodsStore = defineStore("goods", () => {
        //存放对象
        //存放goods的基本信息
        const goods = ref({});
        //拷贝obj的所有内容赋值给shop
        const setGoods = (obj) => {
            goods.value = obj
        }
        //清空容器中的值
        const removeGoods = () => {
            goods.value = {}
        }

        return {
            goods,
            setGoods,
            removeGoods
        }
    },
    //设置参数的持久化
    {
        persist: {
            storage: {
                //调整为兼容多端的api，不同的程序中，存放的位置不同
                setItem(key, value) {
                    uni.setStorageSync(key, value) // [!code warning]
                },
                getItem(key) {
                    return uni.getStorageSync(key) // [!code warning]
                },
            }
        }
    }
)